<?php 
include './include/conf.php';

// On recupere le nom et le prenom des adherents de la base
$select = $pdo->prepare('SELECT nom, prenom FROM Adherent');
$select->execute();

$tabRetour = array();
if($select->rowCount() > 0)
{
	$donnees = array();
	while($user = $select->fetch())
	{
		$donnees[] = $user;	
	}
	$tabRetour['listeAdherents'] = $donnees;
}
else
{
	$tabRetour['listeAdherents'] = "";
}

// On recupere les parcelles non louees
$select = $pdo->prepare('SELECT id_parcelle FROM parcelle where not exists (SELECT * FROM louer where louer.id_parcelle = parcelle.id_parcelle)');
$select->execute();

if($select->rowCount() > 0)
{
	$donnees = array();
	while($user = $select->fetch())
	{
		$donnees[] = $user;
	}
	$tabRetour['listeParcelles'] = $donnees;
}
else
{
	$tabRetour['listeParcelles'] = "";
}

// On recupere les adherents qui louent une parcelle
$select = $pdo->prepare('SELECT nom, prenom, id_parcelle FROM adherent, parcelle where exists (SELECT * FROM louer where louer.id_parcelle = parcelle.id_parcelle AND louer.id_adherent = Adherent.id_adherent)');
$select->execute();

if($select->rowCount() > 0)
{
	$donnees = array();
	while($user = $select->fetch())
	{
		$donnees[] = $user;
	}
	$tabRetour['listeParcellesAdherents'] = $donnees;
}
else
{
	$tabRetour['listeParcellesAdherents'] = "";
}
	echo json_encode($tabRetour); // On renvoit le tableau encode
?>